<?php
	class MCities extends Model {
	
		function __construct() {
			parent::Model();
		}
		
		function getAllCities() {
			$query = $this->db->get('city');
			if ($query->num_rows() > 0){
				return $query->result(); 
			} else {
				show_error('Database is Empty!');
			}  
		}
		
		function getCity($id){
			$options = array('id' => $id);
			$query = $this->db->getwhere('city',$options,1);
			if ($query->num_rows() > 0){
				return $query->result(); 
			}   
		}
		
		function addCity(){
			$data = array( 
				'name' => $_POST['cityname']
			);
			$this->db->insert('city', $data);	
		}
		
		function updateCity($id){
			$data = array( 
				'name' => $_POST['cityname']
				);
			$this->db->where('id', $id);
			$this->db->update('city', $data);	
		}
		
		function deleteCities($id){
			$this->db->where('id', $id);
			$this->db->delete('city');
		}
	}
?>